package com.hxd.otc.module.my.presenter;

import com.hxd.otc.module.my.contract.SilverCertificationPhotoPickerContract;
import com.hxd.otc.module.my.model.UploadImageModel;
import com.hxd.otc.mvp.base.BasePresenter;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class SilverCertificationPhotoPickerPresenter extends BasePresenter<SilverCertificationPhotoPickerContract.IView> implements SilverCertificationPhotoPickerContract.IPresenter {

    private final UploadImageModel mUploadImageModel;

    public SilverCertificationPhotoPickerPresenter(SilverCertificationPhotoPickerContract.IView iView) {
        super(iView);
        mUploadImageModel = UploadImageModel.getInstance();
    }


    @Override
    public void uploadImage(final String tag, File file) {
        mUploadImageModel.uploadCardImage(file, new Observer<String>() {

            @Override
            public void onError(Throwable e) {
                mView.uploadImageFail(tag, e.getMessage());
            }

            @Override
            public void onComplete() {
            }

            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(String result) {
                mView.uploadImageSuccess(tag, result);

            }
        }, mView.<String>bindAutoDispose());
    }
}
